export default filterSentenceForAnalysis = (sentence, oralContent='', isNewMethod=false) => {
    if(!isNewMethod) {
      var _newSentence = sentence.replace(/<br\/>/g, '').replace(/[\.,!?]/g, ' ').replace(/[^a-zA-Z0-9 ]+/g, '');
      return _newSentence.replace(/-/g, ' ').replace(/[ ]+/g, ' ').toUpperCase();
    }

    var _contentForIbm = '';
    var _tokensForReMap = [];
    var _contents = sentence
      .replace(/([\.,!?！？，]) *([A-Z])/g, '$1 $2')
      .replace(/([\.,!?！？，])"([A-Z])/g, '$1 "$2')
      .replace(/([\.,!?！？，])"([a-z])/g, '$1" $2')
      .replace(/[ ]+/g, ' ')
      .replace(/^ /, '')
      .replace(/ $/, '')
      .split(' ');
    _contents.forEach(function(content, index){
      _tokensForReMap.push(
        {
          origin: content,
          forIbm: content.toUpperCase().replace(/^'/, '').replace(/'$/, '')
        }
      );
      content = content.toUpperCase();
      if(content.match(/^I’M$/)){
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/^I’M$/, 'I AM');
      }
      if(content.match(/’RE$/)){
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/’RE$/, ' ARE');
      }
      if(content.match(/’S$/)){
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/’S$/, '');
      }

      if(content.match(/([a-zA-Z0-9]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z]+)/)) {
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm
          .replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z]+)/, 
            function(a, b, c){
              return a + ' at ' + b + ' dot ' + c;
            }
          );
      }

      if(content.match(/FIREFIGHTER/)) {
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/FIREFIGHTER/, 'FIRE FIGHTER');
      }

      if(content.match(/^[0-9]+$/)) {
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/([0-9]+)/, function(a){
          return myApp.services.numberConverter(parseInt(a)).toUpperCase();
        });
      } else
      if(content.match(/[0-9]/)) {
        _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm.replace(/([A-Z])/g, ' $1 ').replace(/([0-9])/g, function(a){
          return ' ' + myApp.services.numberConverter(parseInt(a)).toUpperCase() + ' ';
        });
      }
      _tokensForReMap[index].forIbm = _tokensForReMap[index].forIbm
        .replace(/[^0-9A-Z ']/g, ' ')
        .replace(/[ ]{2,}/g, ' ')
        .replace(/^ /, '')
        .replace(/ $/, ''); 
      _contentForIbm += _tokensForReMap[index].forIbm + ' ';
    });


    if(oralContent && oralContent.length > 0) {
      _contentForIbm = oralContent.replace(/[\(\)]/g, '');
    }

    return {
      origin: _contents.join(' '),
      forAssessment: _contentForIbm.replace(/ $/, ''),
      tokens: _tokensForReMap
    };
    
  }

export const checkName = (val) => {
    var regSam = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？\"\']");
    var reg = new RegExp("[^A-Za-z0-9'-]");
    //var rs = val.replace(reg, '').replace(regSam,'');
    var rs="";
    for (var i = 0, l = val.length; i < val.length; i++) {
        rs = rs + val.substr(i, 1).replace(reg, '');
    }
    return rs;
}

export const getNormalPhone = (raw_phone) => {
    let phoneObject = {
        'AA': 'a:',
        'AA0': 'a:',
        'AA1': 'a:',
        'AA2': 'a:',
        'AE': 'æ',
        'AE0': 'æ',
        'AE1': 'æ',
        'AE2': 'æ',
        'AH': 'ə',
        'AH0': 'ə',
        'AH1': 'ə', //ʌ
        'AH2': 'ə',
        'AO': 'ɔ',
        'AO0': 'ɔ',
        'AO1': 'ɔ',
        'AO2': 'ɔ',
        'AW': 'au',
        'AW0': 'au',
        'AW1': 'au',
        'AW2': 'au',
        'AY': 'ai',
        'AY0': 'ai',
        'AY1': 'ai',
        'AY2': 'ai',
        'B': 'b',
        'CH': 'tʃ',
        'D': 'd',
        'DH': 'ð',
        'EH': 'εə',
        'EH0': 'εə',
        'EH1': 'εə',
        'EH2': 'εə',
        'ER': 'ə:',
        'ER0': 'ə:',
        'ER1': 'ə:',
        'ER2': 'ə:',
        'EY': 'ei',
        'EY0': 'ei',
        'EY1': 'ei',
        'EY2': 'ei',
        'F': 'f',
        'G': 'g',
        'HH': 'h',
        'IH': 'i',
        'IH0': 'i',
        'IH1': 'i',
        'IH2': 'i',
        'IY': 'i:',
        'IY0': 'i:',
        'IY1': 'i:',
        'IY2': 'i:',
        'JH': 'dʒ',
        'K': 'k',
        'L': 'l',
        'M': 'm',
        'N': 'n',
        'NG': 'ŋ',
        'OW': 'əu',
        'OW0': 'əu',
        'OW1': 'əu',
        'OW2': 'əu',
        'OY': 'ɔi',
        'OY0': 'ɔi',
        'OY1': 'ɔi',
        'OY2': 'ɔi',
        'P': 'p',
        'R': 'r',
        'S': 's',
        'SH': 'ʃ',
        'T': 't',
        'TH': 'θ',
        'UH': 'u',
        'UH0': 'u',
        'UH1': 'u',
        'UH2': 'u',
        'UW': 'u:',
        'UW0': 'u:',
        'UW1': 'u:',
        'UW2': 'u:',
        'V': 'v',
        'W': 'w',
        'Y': 'j',
        'Z': 'z',
        'ZH': 'ʒ'
    }
    return phoneObject[raw_phone.replace(/_.*/, "")]
}